local xiejian = fk.CreateSkill {
    name = "ld__xiejian",
}

Fk:loadTranslationTable {
    ["ld__xiejian"] = "挟奸",
    [":ld__xiejian"] = "出牌阶段限一次，你可以对一名其他角色发起“军令”，且你以此法抽取的备选“军令”对其他角色不可见，若其不执行，其强制执行你抽取的备选“军令”。",

    ["#ld__xiejian"] = "挟奸：选择一名其他角色发起“军令”",

    ["$ld__xiejian1"] = "后悔和我作对了吧!",
    ["$ld__xiejian2"] = "既然无路可走，还不闭目待死?",
}

local H = require "packages.ol_hegemony.util"

xiejian:addEffect("active", {
    anim_type = "offensive",
    prompt = "#ld__xiejian",
    can_use = function(self, player)
        return player:usedSkillTimes(xiejian.name, Player.HistoryPhase) == 0
    end,
    target_num = 1,
    card_num = 0,
    target_filter = function(self, player, to_select, selected, selected_cards)
        return #selected == 0 and to_select ~= player
    end,
    times = function (self, player)
      return 1 - player:usedSkillTimes(xiejian.name, Player.HistoryPhase)
    end,
    card_filter = Util.FalseFunc,
    on_use = function(self, room, effect)
        local player = effect.from
        local to = effect.tos[1]
        --选择军令执行
        local allCommands = { "command1", "command2", "command3", "command4", "command5", "command6" }
        local commands = table.random(allCommands, 2) ---@type string[]
        local choice = room:askToChoice(player, { choices = commands, skill_name = "start_command", detailed = true }) --选择一个军令
        room:sendLog {
            type = "#CommandChoice",
            from = player.id,
            arg = ":" + choice,
            toast = true,
        }
        
        local index = table.indexOf(allCommands, choice) --明的军令
        local cards = {"Command1", "Command2", "Command3", "Command4", "Command5", "Command6"}
        local card = Fk:cloneCard(cards[table.indexOf(allCommands, choice)])
        room:getVirtCardId(card)
        room:showVirtualCard(card, player, nil, room.logic:getCurrentEvent().id + 1)
        --军令特效
        table.removeOne(commands, choice)
        local spare_index = commands[1]                  --备用军令
        if player.dead or to.dead then return false end
        --开始执行军令
        room:sendLog {
            type = "#AskCommandTo",
            from = player.id,
            to = { to.id },
            arg = xiejian.name,
            toast = true,
        }
        if not H.doCommand(to, xiejian.name, index, player, false) then
            H.doCommand(to, xiejian.name, table.indexOf(allCommands, spare_index), player, true)
        end
    end,
})

return xiejian
